package alittlepond;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

public class Thing {

	private static Point[] MOVE_OPTIONS = {new Point(0, 1),new Point(1, 0),new Point(0, -1),new Point(-1, 0), new Point(1, 1),new Point(-1, 1),new Point(1, -1),new Point(-1, -1)};
	
	
	private int posX;
	private int posY;
	private BlurPanel blurPanel;
	public Thing(int posX, int posY, BlurPanel blurPanel) {
		super();
		this.posX = posX;
		this.posY = posY;
		this.blurPanel = blurPanel;
	}
	
	public void move() {
		Point moveTo = null;
		double currentValue = blurPanel.getValue(posX, posY);
		
		for (Point p : MOVE_OPTIONS) {
			p = new Point(p.x + posX, p.y + posY);
			
			double targetValue = blurPanel.getValue(p.x, p.y);
			if(targetValue > currentValue) {
				currentValue = targetValue;
				moveTo = p;
			}
			
		}
		
		if(moveTo != null) {
			posX = blurPanel.getX(moveTo.x);
			posY = blurPanel.getY(moveTo.y);
		}
		
	}

	public void draw(Graphics g) {
		g.setColor(Color.red);
		g.fillRect(posX-2, posY-2, 4, 4);
		g.setColor(Color.blue);
		g.drawString("(" + posX + ", " + posY + ")", posX, posY + 10);
	}
	
}
